(Abridged) Precision cosmology with Type Ia supernovae (SNe Ia) makes use of the fact that SN Ia luminosities depend on their light-curve shapes and colours. Using Supernova Legacy Survey (SNLS) and other data, we show that there is an additional dependence on the global characteristics of their host galaxies: events of the same light-curve shape and colour are, on average, 0.08mag (~4.0sigma) brighter in massive host galaxies (presumably metal-rich) and galaxies with low specific star-formation rates (sSFR). SNe Ia in galaxies with a low sSFR also have a smaller slope ("beta") between their luminosities and colours with ~2.7sigma significance, and a smaller scatter on SN Ia Hubble diagrams (at 95% confidence), though the significance of these effects is dependent on the reddest SNe. SN Ia colours are similar between low-mass and high-mass hosts, leading us to interpret their luminosity differences as an intrinsic property of the SNe and not of some external factor such as dust. If the host stellar mass is interpreted as a metallicity indicator, the luminosity trends are in qualitative agreement with theoretical predictions. We show that the average stellar mass, and therefore the average metallicity, of our SN Ia host galaxies decreases with redshift. The SN Ia luminosity differences consequently introduce a systematic error in cosmological analyses, comparable to the current statistical uncertainties on parameters such as w. We show that the use of two SN Ia absolute magnitudes, one for events in high-mass (metal-rich) galaxies, and one for events in low-mass (metal-poor) galaxies, adequately corrects for the differences. Cosmological fits incorporating these terms give a significant reduction in chi^2 (3.8-4.5sigma). We conclude that future SN Ia cosmological analyses should use a correction of this (or similar) form to control demographic shifts in the galaxy population.